home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_12_10
/
saks
/
strtst6.cpp
< prev
Wrap
C/C++ Source or Header
|
1994-08-08
|
2KB
|
76 lines
Listing 9 - a test program for comqs as a queue of str
//
// strtst6.cpp - test comq6 using str elements
//
#include <iostream.h>
#include "comq6.h"
#include "comstr6.h"
#include "showheap.h"
ostream &operator<<(ostream &os, comq &q)
{
comstr *ps;
comq::iterator cqi(q);
while ((ps = (comstr *)cqi.next()) != 0)
os << ' ' << *ps;
return os;
}
#define DIM(a) (sizeof(a)/sizeof(a[0]))
void test()
{
char c;
size_t qn;
comstr qe;
comq q[4];
while (cin >> c)
{
showheap();
if (c == 'q')
break;
if (c == 'a')
{
cin >> qn >> qe;
if (qn >= DIM(q))
cout << "no such queue\n";
else
q[qn].append(qe);
}
else if (c == 'c')
{
cin >> qn;
if (qn >= DIM(q))
cout << "no such queue\n";
else
q[qn].clear();
}
else if (c == 'r')
{
cin >> qn;
if (qn >= DIM(q))
cout << "no such queue\n";
else if (q[qn].remove(qe))
cout << "removed " << qe << '\n';
else
cout << "q[" << qn << "] is empty\n";
}
else
continue;
for (size_t i = 0; i < DIM(q); ++i)
cout << i << ':' << q[i] << '\n';
}
}
int main()
{
showheap();
test();
showheap();
return 0;
}